import 'package:boss/color_constant.dart';
import 'package:boss/textStyle/text_style.dart';
import 'package:hi_common/hi_common.dart';
import 'package:flutter/material.dart';

class CustomListTitle extends StatelessWidget {
  final dynamic title;
  final dynamic subTitle;
  final int childHeight;
  final dynamic trailing;
  final VoidCallback onTap;
  final bool isHideDivider;

  const CustomListTitle({
    Key key,
    @required this.title,
    this.trailing,
    this.subTitle,
    this.childHeight,
    this.onTap,
    this.isHideDivider = false,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    Widget child = Container(
      height: childHeight == null ? 90.w : ScreenUtil.instance.setWidth(double.parse(childHeight.toString())),
      color: Colors.white,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: <Widget>[
          title is String ? Expanded(child: Text(title, style: TextStyleConstant().normal_1_28, maxLines: 1)) : title,
          _buildTrailing(),
        ],
      ),
    );

    if (subTitle != null) {
      child = Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          child,
          Container(
            margin: EdgeInsets.only(bottom: 18.w),
            child: subTitle is String ? Text(subTitle, style: TextStyleConstant().normal_4_24) : subTitle,
          ),
        ],
      );
    }

    return GestureDetector(
      onTap: onTap,
      behavior: HitTestBehavior.translucent,
      child: Container(
        child: child,
        decoration: BoxDecoration(
          border: isHideDivider ? null : Border(bottom: BorderSide(color: ColorConstant.e6e6, width: 1.px)),
        ),
      ),
    );
  }

  Widget _buildTrailing() {
    if (trailing is Widget) {
      return trailing;
    }

    if (trailing is String) {
      return Expanded(child: Text(trailing, style: TextStyleConstant().normal_1_28, overflow: TextOverflow.ellipsis));
    }

    return SizedBox();
  }
}
